package zpp_nape.geom;
import zpp_nape.Config;
import zpp_nape.Const;
import zpp_nape.util.Flags;
import DummyNapeMain;
import zpp_nape.util.Math;
import zpp_nape.util.Names;
import zpp_nape.util.Pool;
import zpp_nape.util.Lists;
import zpp_nape.shape.Circle;
import zpp_nape.shape.Edge;
import zpp_nape.space.Space;
import zpp_nape.shape.Polygon;
import zpp_nape.shape.Shape;
import zpp_nape.phys.FeatureMix;
import zpp_nape.phys.FluidProperties;
import zpp_nape.phys.Material;
import zpp_nape.phys.Body;
import zpp_nape.geom.AABB;
import zpp_nape.geom.Mat23;
import zpp_nape.geom.Vec2;
import zpp_nape.geom.VecMath;
import zpp_nape.geom.Collide;
import zpp_nape.dynamics.Arbiter;
import zpp_nape.dynamics.Contact;
import zpp_nape.dynamics.InteractionFilter;
import zpp_nape.constraint.Constraint;
import zpp_nape.dynamics.SpaceArbiterList;
import zpp_nape.constraint.Matrices;
import zpp_nape.constraint.PivotJoint;
import zpp_nape.constraint.WeldJoint;
import nape.util.Flags;
import nape.util.Lists;
import nape.util.Debug;
import nape.space.Space;
import nape.shape.Circle;
import nape.shape.Polygon;
import nape.shape.Edge;
import nape.shape.Shape;
import nape.phys.FluidProperties;
import nape.phys.Material;
import nape.phys.Body;
import nape.geom.AABB;
import nape.geom.Geom;
import nape.geom.Mat23;
import nape.geom.Vec2;
import nape.dynamics.Contact;
import nape.dynamics.Arbiter;
import nape.dynamics.InteractionFilter;
#if swc@:keep#end class ZPP_Distance{
    public static inline function distance(outa:ZPP_Vec2,outb:ZPP_Vec2,s1:ZPP_Shape,s2:ZPP_Shape,cache:ZPP_SCache){
        if(s2.isPolygon()){
            return if(s1.isPolygon()){
                var id=(s1.polygon.id<s2.polygon.id?({
                    #if NAPE_ASSERT var A=s1.polygon.id;
                    var B=s2.polygon.id;
                    {
                        #if NAPE_ASSERT var res={
                            A<=B;
                        };
                        if(!res)throw "assert("+"A<=B"+") :: "+("ordered_id(in a: "+"s1.polygon.id"+", in b: "+"s2.polygon.id"+")");
                        #end
                    };
                    (A<<16)|B;
                    #else((s1.polygon.id)<<16)|(s2.polygon.id);
                    #end
                }):({
                    #if NAPE_ASSERT var A=s2.polygon.id;
                    var B=s1.polygon.id;
                    {
                        #if NAPE_ASSERT var res={
                            A<=B;
                        };
                        if(!res)throw "assert("+"A<=B"+") :: "+("ordered_id(in a: "+"s2.polygon.id"+", in b: "+"s1.polygon.id"+")");
                        #end
                    };
                    (A<<16)|B;
                    #else((s2.polygon.id)<<16)|(s1.polygon.id);
                    #end
                }));
                if(cache==null){
                    cache=defcache;
                    cache.set(s1.polygon,s2.polygon);
                }
                cache.validate();
                var count=cache.count;
                var v1=cache.v1;
                var v2=cache.v2;
                var v3=cache.v3;
                var ida=[];
                var idb=[];
                var ind=0;
                while(ind++<2000){
                    var pcount=count;
                    ida[0]=v1.ia;
                    idb[0]=v1.ib;
                    if(count>=2){
                        ida[1]=v2.ia;
                        idb[1]=v2.ib;
                    }
                    if(count==3){
                        ida[2]=v3.ia;
                        idb[2]=v3.ib;
                    }
                    if(count==2){
                        var ex:Float;
                        var ey:Float;
                        {
                            ex=v2.vx-v1.vx;
                            ey=v2.vy-v1.vy;
                        };
                        var d2=-(v1.vx*ex+v1.vy*ey);
                        if(d2<=0.0){
                            v1.w=1.0;
                            count=1;
                        }
                        else{
                            var d1=(v2.vx*ex+v2.vy*ey);
                            if(d1<=0.0){
                                v2.w=1.0;
                                count=1;
                                {
                                    var t=v1;
                                    v1=v2;
                                    v2=t;
                                };
                            }
                            else{
                                var id=1/(d1+d2);
                                v1.w=d1*id;
                                v2.w=d2*id;
                            }
                        }
                    };
                    else if(count==3){
                        var e12x:Float;
                        var e12y:Float;
                        {
                            e12x=v2.vx-v1.vx;
                            e12y=v2.vy-v1.vy;
                        };
                        var d12_1=(v2.vx*e12x+v2.vy*e12y);
                        var d12_2=-(v1.vx*e12x+v1.vy*e12y);
                        var e13x:Float;
                        var e13y:Float;
                        {
                            e13x=v3.vx-v1.vx;
                            e13y=v3.vy-v1.vy;
                        };
                        var d13_1=(v3.vx*e13x+v3.vy*e13y);
                        var d13_2=-(v1.vx*e13x+v1.vy*e13y);
                        var e23x:Float;
                        var e23y:Float;
                        {
                            e23x=v3.vx-v2.vx;
                            e23y=v3.vy-v2.vy;
                        };
                        var d23_1=(v3.vx*e23x+v3.vy*e23y);
                        var d23_2=-(v2.vx*e23x+v2.vy*e23y);
                        var dn=(e13y*e12x-e13x*e12y);
                        var d1=dn*(v3.vy*v2.vx-v3.vx*v2.vy);
                        var d2=dn*(v1.vy*v3.vx-v1.vx*v3.vy);
                        var d3=dn*(v2.vy*v1.vx-v2.vx*v1.vy);
                        if(d12_2<=0.0&&d13_2<=0.0){
                            v1.w=1.0;
                            count=1;
                        }
                        else if(d12_1>0.0&&d12_2>0.0&&d3<=0.0){
                            var id=1.0/(d12_1+d12_2);
                            v1.w=d12_1*id;
                            v2.w=d12_2*id;
                            count=2;
                        }
                        else if(d13_1>0.0&&d13_2>0.0&&d2<=0.0){
                            var id=1.0/(d13_1+d13_2);
                            v1.w=d13_1*id;
                            v3.w=d13_2*id;
                            count=2;
                            {
                                var t=v2;
                                v2=v3;
                                v3=t;
                            };
                        }
                        else if(d12_1<=0.0&&d23_2<=0.0){
                            v2.w=1.0;
                            count=1;
                            {
                                var t=v1;
                                v1=v2;
                                v2=t;
                            };
                        }
                        else if(d13_1<=0.0&&d23_1<=0.0){
                            v3.w=1.0;
                            count=1;
                            {
                                var t=v1;
                                v1=v3;
                                v3=t;
                            };
                        }
                        else if(d23_1>0.0&&d23_2>0.0&&d1<=0.0){
                            var id=1.0/(d23_1+d23_2);
                            v2.w=d23_1*id;
                            v3.w=d23_2*id;
                            count=2;
                            {
                                var t=v1;
                                v1=v3;
                                v3=t;
                            };
                        }
                        else{
                            var id=1.0/(d1+d2+d3);
                            v1.w=d1*id;
                            v2.w=d2*id;
                            v3.w=d3*id;
                        }
                    };
                    if(count==3)break;
                    var dx:Float;
                    var dy:Float;
                    {
                        if(count==1){
                            dx=-v1.vx;
                            dy=-v1.vy;
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](dx);
                                        ret;
                                        #else Math.isNaN(dx);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(dx)"+") :: "+("vec_set(in n: "+"d"+",in x: "+"-v1.vx"+",in y: "+"-v1.vy"+")");
                                #end
                            };
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](dy);
                                        ret;
                                        #else Math.isNaN(dy);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(dy)"+") :: "+("vec_set(in n: "+"d"+",in x: "+"-v1.vx"+",in y: "+"-v1.vy"+")");
                                #end
                            };
                        };
                        else if(count==2){
                            var ex:Float;
                            var ey:Float;
                            {
                                ex=v2.vx-v1.vx;
                                ey=v2.vy-v1.vy;
                            };
                            var sgn=(ey*v1.vx-ex*v1.vy);
                            if(sgn>0){
                                dx=-ey;
                                dy=ex;
                                {
                                    #if NAPE_ASSERT var res={
                                        !({
                                            #if flash9 var ret:Bool=untyped __global__["isNaN"](dx);
                                            ret;
                                            #else Math.isNaN(dx);
                                            #end
                                        });
                                    };
                                    if(!res)throw "assert("+"!assert_isNaN(dx)"+") :: "+("vec_set(in n: "+"d"+",in x: "+"-ey"+",in y: "+"ex"+")");
                                    #end
                                };
                                {
                                    #if NAPE_ASSERT var res={
                                        !({
                                            #if flash9 var ret:Bool=untyped __global__["isNaN"](dy);
                                            ret;
                                            #else Math.isNaN(dy);
                                            #end
                                        });
                                    };
                                    if(!res)throw "assert("+"!assert_isNaN(dy)"+") :: "+("vec_set(in n: "+"d"+",in x: "+"-ey"+",in y: "+"ex"+")");
                                    #end
                                };
                            };
                            else{
                                dx=ey;
                                dy=-ex;
                                {
                                    #if NAPE_ASSERT var res={
                                        !({
                                            #if flash9 var ret:Bool=untyped __global__["isNaN"](dx);
                                            ret;
                                            #else Math.isNaN(dx);
                                            #end
                                        });
                                    };
                                    if(!res)throw "assert("+"!assert_isNaN(dx)"+") :: "+("vec_set(in n: "+"d"+",in x: "+"ey"+",in y: "+"-ex"+")");
                                    #end
                                };
                                {
                                    #if NAPE_ASSERT var res={
                                        !({
                                            #if flash9 var ret:Bool=untyped __global__["isNaN"](dy);
                                            ret;
                                            #else Math.isNaN(dy);
                                            #end
                                        });
                                    };
                                    if(!res)throw "assert("+"!assert_isNaN(dy)"+") :: "+("vec_set(in n: "+"d"+",in x: "+"ey"+",in y: "+"-ex"+")");
                                    #end
                                };
                            };
                        }
                        else{
                            dx=0;
                            dy=0;
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](dx);
                                        ret;
                                        #else Math.isNaN(dx);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(dx)"+") :: "+("vec_set(in n: "+"d"+",in x: "+"0"+",in y: "+"0"+")");
                                #end
                            };
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](dy);
                                        ret;
                                        #else Math.isNaN(dy);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(dy)"+") :: "+("vec_set(in n: "+"d"+",in x: "+"0"+",in y: "+"0"+")");
                                #end
                            };
                        };
                    };
                    if((dx*dx+dy*dy)<ZPP_Const.EPSILON)break;
                    var vertex=(count==1?v2:v3);
                    {
                        vertex.ia=0;
                        var best=s1.polygon.gverts.front();
                        var bestv=(best.x*dx+best.y*dy)*-1.0;
                        var ind=1;
                        {
                            var cx_ite=s1.polygon.gverts.begin().next;
                            while(cx_ite!=null){
                                var vert=cx_ite.elem();
                                {
                                    var value=(vert.x*dx+vert.y*dy)*-1.0;
                                    if(value>bestv){
                                        bestv=value;
                                        best=vert;
                                        vertex.ia=ind;
                                    }
                                    ind++;
                                };
                                cx_ite=cx_ite.next;
                            }
                        };
                        vertex.a=best;
                        {
                            vertex.ax=best.x;
                            vertex.ay=best.y;
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](vertex.ax);
                                        ret;
                                        #else Math.isNaN(vertex.ax);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(vertex.ax)"+") :: "+("vec_set(in n: "+"vertex.a"+",in x: "+"best.x"+",in y: "+"best.y"+")");
                                #end
                            };
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](vertex.ay);
                                        ret;
                                        #else Math.isNaN(vertex.ay);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(vertex.ay)"+") :: "+("vec_set(in n: "+"vertex.a"+",in x: "+"best.x"+",in y: "+"best.y"+")");
                                #end
                            };
                        };
                    };
                    {
                        vertex.ib=0;
                        var best=s2.polygon.gverts.front();
                        var bestv=(best.x*dx+best.y*dy)*1.0;
                        var ind=1;
                        {
                            var cx_ite=s2.polygon.gverts.begin().next;
                            while(cx_ite!=null){
                                var vert=cx_ite.elem();
                                {
                                    var value=(vert.x*dx+vert.y*dy)*1.0;
                                    if(value>bestv){
                                        bestv=value;
                                        best=vert;
                                        vertex.ib=ind;
                                    }
                                    ind++;
                                };
                                cx_ite=cx_ite.next;
                            }
                        };
                        vertex.b=best;
                        {
                            vertex.bx=best.x;
                            vertex.by=best.y;
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](vertex.bx);
                                        ret;
                                        #else Math.isNaN(vertex.bx);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(vertex.bx)"+") :: "+("vec_set(in n: "+"vertex.b"+",in x: "+"best.x"+",in y: "+"best.y"+")");
                                #end
                            };
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](vertex.by);
                                        ret;
                                        #else Math.isNaN(vertex.by);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(vertex.by)"+") :: "+("vec_set(in n: "+"vertex.b"+",in x: "+"best.x"+",in y: "+"best.y"+")");
                                #end
                            };
                        };
                    };
                    {
                        vertex.vx=vertex.bx-vertex.ax;
                        vertex.vy=vertex.by-vertex.ay;
                    };
                    var dup=false;
                    for(i in 0...pcount){
                        if(vertex.ia==ida[i]&&vertex.ib==idb[i]){
                            dup=true;
                            break;
                        }
                    }
                    if(dup)break;
                    count++;
                }
                if(cache!=defcache)cache.write(count,v1,v2,v3);
                if(count==1){
                    {
                        outa.x=v1.ax;
                        outa.y=v1.ay;
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](outa.x);
                                    ret;
                                    #else Math.isNaN(outa.x);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(outa.x)"+") :: "+("vec_set(in n: "+"outa."+",in x: "+"v1.ax"+",in y: "+"v1.ay"+")");
                            #end
                        };
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](outa.y);
                                    ret;
                                    #else Math.isNaN(outa.y);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(outa.y)"+") :: "+("vec_set(in n: "+"outa."+",in x: "+"v1.ax"+",in y: "+"v1.ay"+")");
                            #end
                        };
                    };
                    {
                        outb.x=v1.bx;
                        outb.y=v1.by;
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](outb.x);
                                    ret;
                                    #else Math.isNaN(outb.x);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(outb.x)"+") :: "+("vec_set(in n: "+"outb."+",in x: "+"v1.bx"+",in y: "+"v1.by"+")");
                            #end
                        };
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](outb.y);
                                    ret;
                                    #else Math.isNaN(outb.y);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(outb.y)"+") :: "+("vec_set(in n: "+"outb."+",in x: "+"v1.bx"+",in y: "+"v1.by"+")");
                            #end
                        };
                    };
                    Math.sqrt(({
                        var dx:Float;
                        var dy:Float;
                        {
                            dx=outa.x-outb.x;
                            dy=outa.y-outb.y;
                        };
                        (dx*dx+dy*dy);
                    }));
                }
                else if(count==2){
                    {
                        outa.x=0;
                        outa.y=0;
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](outa.x);
                                    ret;
                                    #else Math.isNaN(outa.x);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(outa.x)"+") :: "+("vec_set(in n: "+"outa."+",in x: "+"0"+",in y: "+"0"+")");
                            #end
                        };
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](outa.y);
                                    ret;
                                    #else Math.isNaN(outa.y);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(outa.y)"+") :: "+("vec_set(in n: "+"outa."+",in x: "+"0"+",in y: "+"0"+")");
                            #end
                        };
                    };
                    {
                        var t=(v1.w);
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                    ret;
                                    #else Math.isNaN(t);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_addeq(in a: "+"outa."+",in b: "+"v1.a"+",in s: "+"v1.w"+")");
                            #end
                        };
                        outa.x+=v1.ax*t;
                        outa.y+=v1.ay*t;
                    };
                    {
                        var t=(v2.w);
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                    ret;
                                    #else Math.isNaN(t);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_addeq(in a: "+"outa."+",in b: "+"v2.a"+",in s: "+"v2.w"+")");
                            #end
                        };
                        outa.x+=v2.ax*t;
                        outa.y+=v2.ay*t;
                    };
                    {
                        outb.x=0;
                        outb.y=0;
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](outb.x);
                                    ret;
                                    #else Math.isNaN(outb.x);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(outb.x)"+") :: "+("vec_set(in n: "+"outb."+",in x: "+"0"+",in y: "+"0"+")");
                            #end
                        };
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](outb.y);
                                    ret;
                                    #else Math.isNaN(outb.y);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(outb.y)"+") :: "+("vec_set(in n: "+"outb."+",in x: "+"0"+",in y: "+"0"+")");
                            #end
                        };
                    };
                    {
                        var t=(v1.w);
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                    ret;
                                    #else Math.isNaN(t);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_addeq(in a: "+"outb."+",in b: "+"v1.b"+",in s: "+"v1.w"+")");
                            #end
                        };
                        outb.x+=v1.bx*t;
                        outb.y+=v1.by*t;
                    };
                    {
                        var t=(v2.w);
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                    ret;
                                    #else Math.isNaN(t);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_addeq(in a: "+"outb."+",in b: "+"v2.b"+",in s: "+"v2.w"+")");
                            #end
                        };
                        outb.x+=v2.bx*t;
                        outb.y+=v2.by*t;
                    };
                    Math.sqrt(({
                        var dx:Float;
                        var dy:Float;
                        {
                            dx=outa.x-outb.x;
                            dy=outa.y-outb.y;
                        };
                        (dx*dx+dy*dy);
                    }));
                }
                else-1.0;
            };
            else{
                var max=-ZPP_Const.FMAX;
                var a0=null,vi=null;
                var vite=s2.polygon.gverts.begin();
                {
                    var cx_ite=s2.polygon.edges.begin();
                    while(cx_ite!=null){
                        var a=cx_ite.elem();
                        {
                            var dist=(a.gnormx*s1.circle.worldCOMx+a.gnormy*s1.circle.worldCOMy)-a.gprojection-s1.circle.radius;
                            if(dist>max){
                                max=dist;
                                a0=a;
                                vi=vite;
                            }
                            vite=vite.next;
                        };
                        cx_ite=cx_ite.next;
                    }
                };
                var v0=vi.elem();
                var v1=if(vi.next==null)s2.polygon.gverts.front()else vi.next.elem();
                var dt=(s1.circle.worldCOMy*a0.gnormx-s1.circle.worldCOMx*a0.gnormy);
                if(dt<=(v0.y*a0.gnormx-v0.x*a0.gnormy)){
                    var dx:Float;
                    var dy:Float;
                    {
                        dx=v0.x-s1.circle.worldCOMx;
                        dy=v0.y-s1.circle.worldCOMy;
                    };
                    var r=s1.circle.radius+0;
                    var dl=(dx*dx+dy*dy);
                    if(dl<r*r)-1.0;
                    else{
                        var id=ZPP_Math.invsqrt(dl);
                        {
                            var t=(id);
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                        ret;
                                        #else Math.isNaN(t);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_muleq(in a: "+"d"+",in s: "+"id"+")");
                                #end
                            };
                            dx*=t;
                            dy*=t;
                        };
                        {
                            outa.x=s1.circle.worldCOMx;
                            outa.y=s1.circle.worldCOMy;
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](outa.x);
                                        ret;
                                        #else Math.isNaN(outa.x);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(outa.x)"+") :: "+("vec_set(in n: "+"outa."+",in x: "+"s1.circle.worldCOMx"+",in y: "+"s1.circle.worldCOMy"+")");
                                #end
                            };
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](outa.y);
                                        ret;
                                        #else Math.isNaN(outa.y);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(outa.y)"+") :: "+("vec_set(in n: "+"outa."+",in x: "+"s1.circle.worldCOMx"+",in y: "+"s1.circle.worldCOMy"+")");
                                #end
                            };
                        };
                        {
                            var t=(s1.circle.radius);
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                        ret;
                                        #else Math.isNaN(t);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_addeq(in a: "+"outa."+",in b: "+"d"+",in s: "+"s1.circle.radius"+")");
                                #end
                            };
                            outa.x+=dx*t;
                            outa.y+=dy*t;
                        };
                        {
                            outb.x=v0.x;
                            outb.y=v0.y;
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](outb.x);
                                        ret;
                                        #else Math.isNaN(outb.x);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(outb.x)"+") :: "+("vec_set(in n: "+"outb."+",in x: "+"v0.x"+",in y: "+"v0.y"+")");
                                #end
                            };
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](outb.y);
                                        ret;
                                        #else Math.isNaN(outb.y);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(outb.y)"+") :: "+("vec_set(in n: "+"outb."+",in x: "+"v0.x"+",in y: "+"v0.y"+")");
                                #end
                            };
                        };
                        {
                            var t=(0);
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                        ret;
                                        #else Math.isNaN(t);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_subeq(in a: "+"outb."+",in b: "+"d"+",in s: "+"0"+")");
                                #end
                            };
                            outb.x-=dx*t;
                            outb.y-=dy*t;
                        };
                        1/id-r;
                    }
                }
                else if(dt>=(v1.y*a0.gnormx-v1.x*a0.gnormy)){
                    var dx:Float;
                    var dy:Float;
                    {
                        dx=v1.x-s1.circle.worldCOMx;
                        dy=v1.y-s1.circle.worldCOMy;
                    };
                    var r=s1.circle.radius+0;
                    var dl=(dx*dx+dy*dy);
                    if(dl<r*r)-1.0;
                    else{
                        var id=ZPP_Math.invsqrt(dl);
                        {
                            var t=(id);
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                        ret;
                                        #else Math.isNaN(t);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_muleq(in a: "+"d"+",in s: "+"id"+")");
                                #end
                            };
                            dx*=t;
                            dy*=t;
                        };
                        {
                            outa.x=s1.circle.worldCOMx;
                            outa.y=s1.circle.worldCOMy;
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](outa.x);
                                        ret;
                                        #else Math.isNaN(outa.x);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(outa.x)"+") :: "+("vec_set(in n: "+"outa."+",in x: "+"s1.circle.worldCOMx"+",in y: "+"s1.circle.worldCOMy"+")");
                                #end
                            };
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](outa.y);
                                        ret;
                                        #else Math.isNaN(outa.y);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(outa.y)"+") :: "+("vec_set(in n: "+"outa."+",in x: "+"s1.circle.worldCOMx"+",in y: "+"s1.circle.worldCOMy"+")");
                                #end
                            };
                        };
                        {
                            var t=(s1.circle.radius);
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                        ret;
                                        #else Math.isNaN(t);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_addeq(in a: "+"outa."+",in b: "+"d"+",in s: "+"s1.circle.radius"+")");
                                #end
                            };
                            outa.x+=dx*t;
                            outa.y+=dy*t;
                        };
                        {
                            outb.x=v1.x;
                            outb.y=v1.y;
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](outb.x);
                                        ret;
                                        #else Math.isNaN(outb.x);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(outb.x)"+") :: "+("vec_set(in n: "+"outb."+",in x: "+"v1.x"+",in y: "+"v1.y"+")");
                                #end
                            };
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](outb.y);
                                        ret;
                                        #else Math.isNaN(outb.y);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(outb.y)"+") :: "+("vec_set(in n: "+"outb."+",in x: "+"v1.x"+",in y: "+"v1.y"+")");
                                #end
                            };
                        };
                        {
                            var t=(0);
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                        ret;
                                        #else Math.isNaN(t);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_subeq(in a: "+"outb."+",in b: "+"d"+",in s: "+"0"+")");
                                #end
                            };
                            outb.x-=dx*t;
                            outb.y-=dy*t;
                        };
                        1/id-r;
                    }
                }
                else if(max>=0.0){
                    {
                        outa.x=s1.circle.worldCOMx;
                        outa.y=s1.circle.worldCOMy;
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](outa.x);
                                    ret;
                                    #else Math.isNaN(outa.x);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(outa.x)"+") :: "+("vec_set(in n: "+"outa."+",in x: "+"s1.circle.worldCOMx"+",in y: "+"s1.circle.worldCOMy"+")");
                            #end
                        };
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](outa.y);
                                    ret;
                                    #else Math.isNaN(outa.y);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(outa.y)"+") :: "+("vec_set(in n: "+"outa."+",in x: "+"s1.circle.worldCOMx"+",in y: "+"s1.circle.worldCOMy"+")");
                            #end
                        };
                    };
                    {
                        var t=(s1.circle.radius);
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                    ret;
                                    #else Math.isNaN(t);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_subeq(in a: "+"outa."+",in b: "+"a0.gnorm"+",in s: "+"s1.circle.radius"+")");
                            #end
                        };
                        outa.x-=a0.gnormx*t;
                        outa.y-=a0.gnormy*t;
                    };
                    {
                        outb.x=outa.x;
                        outb.y=outa.y;
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](outb.x);
                                    ret;
                                    #else Math.isNaN(outb.x);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(outb.x)"+") :: "+("vec_set(in n: "+"outb."+",in x: "+"outa.x"+",in y: "+"outa.y"+")");
                            #end
                        };
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](outb.y);
                                    ret;
                                    #else Math.isNaN(outb.y);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(outb.y)"+") :: "+("vec_set(in n: "+"outb."+",in x: "+"outa.x"+",in y: "+"outa.y"+")");
                            #end
                        };
                    };
                    {
                        var t=(max);
                        {
                            #if NAPE_ASSERT var res={
                                !({
                                    #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                    ret;
                                    #else Math.isNaN(t);
                                    #end
                                });
                            };
                            if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_subeq(in a: "+"outb."+",in b: "+"a0.gnorm"+",in s: "+"max"+")");
                            #end
                        };
                        outb.x-=a0.gnormx*t;
                        outb.y-=a0.gnormy*t;
                    };
                    max;
                }
                else-1.0;
            };
        }
        else return{
            var dx:Float;
            var dy:Float;
            {
                dx=s2.circle.worldCOMx-s1.circle.worldCOMx;
                dy=s2.circle.worldCOMy-s1.circle.worldCOMy;
            };
            var r=s1.circle.radius+s2.circle.radius;
            var dl=(dx*dx+dy*dy);
            if(dl<r*r)-1.0;
            else{
                var id=ZPP_Math.invsqrt(dl);
                {
                    var t=(id);
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                ret;
                                #else Math.isNaN(t);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_muleq(in a: "+"d"+",in s: "+"id"+")");
                        #end
                    };
                    dx*=t;
                    dy*=t;
                };
                {
                    outa.x=s1.circle.worldCOMx;
                    outa.y=s1.circle.worldCOMy;
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](outa.x);
                                ret;
                                #else Math.isNaN(outa.x);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(outa.x)"+") :: "+("vec_set(in n: "+"outa."+",in x: "+"s1.circle.worldCOMx"+",in y: "+"s1.circle.worldCOMy"+")");
                        #end
                    };
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](outa.y);
                                ret;
                                #else Math.isNaN(outa.y);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(outa.y)"+") :: "+("vec_set(in n: "+"outa."+",in x: "+"s1.circle.worldCOMx"+",in y: "+"s1.circle.worldCOMy"+")");
                        #end
                    };
                };
                {
                    var t=(s1.circle.radius);
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                ret;
                                #else Math.isNaN(t);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_addeq(in a: "+"outa."+",in b: "+"d"+",in s: "+"s1.circle.radius"+")");
                        #end
                    };
                    outa.x+=dx*t;
                    outa.y+=dy*t;
                };
                {
                    outb.x=s2.circle.worldCOMx;
                    outb.y=s2.circle.worldCOMy;
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](outb.x);
                                ret;
                                #else Math.isNaN(outb.x);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(outb.x)"+") :: "+("vec_set(in n: "+"outb."+",in x: "+"s2.circle.worldCOMx"+",in y: "+"s2.circle.worldCOMy"+")");
                        #end
                    };
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](outb.y);
                                ret;
                                #else Math.isNaN(outb.y);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(outb.y)"+") :: "+("vec_set(in n: "+"outb."+",in x: "+"s2.circle.worldCOMx"+",in y: "+"s2.circle.worldCOMy"+")");
                        #end
                    };
                };
                {
                    var t=(s2.circle.radius);
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                ret;
                                #else Math.isNaN(t);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_subeq(in a: "+"outb."+",in b: "+"d"+",in s: "+"s2.circle.radius"+")");
                        #end
                    };
                    outb.x-=dx*t;
                    outb.y-=dy*t;
                };
                1/id-r;
            }
        };
    }
    public static var defcache=new ZPP_SCache();
}
#if swc@:keep#end class ZPP_SVertex{
    public var ia:Int;
    public var ib:Int;
    public var a:ZPP_Vec2;
    public var b:ZPP_Vec2;
    public var ax:Float;
    public var ay:Float;
    public var bx:Float;
    public var by:Float;
    public var vx:Float;
    public var vy:Float;
    public var w:Float;
    public function new(){}
}
#if swc@:keep#end class ZPP_SCache{
    public var metric:Float;
    public var count:Int;
    public var v1:ZPP_SVertex;
    public var v2:ZPP_SVertex;
    public var v3:ZPP_SVertex;
    public var p1:ZPP_Polygon;
    public var p2:ZPP_Polygon;
    public function new(){}
    #if(flash9&&flib)@:ns("flibdel")#end public inline function set(p1:ZPP_Polygon,p2:ZPP_Polygon){
        v1=new ZPP_SVertex();
        v2=new ZPP_SVertex();
        v3=new ZPP_SVertex();
        this.p1=p1;
        this.p2=p2;
        count=0;
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function validate(){
        if(count!=0){
            {
                v1.ax=v1.a.x;
                v1.ay=v1.a.y;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](v1.ax);
                            ret;
                            #else Math.isNaN(v1.ax);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(v1.ax)"+") :: "+("vec_set(in n: "+"v1.a"+",in x: "+"v1.a.x"+",in y: "+"v1.a.y"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](v1.ay);
                            ret;
                            #else Math.isNaN(v1.ay);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(v1.ay)"+") :: "+("vec_set(in n: "+"v1.a"+",in x: "+"v1.a.x"+",in y: "+"v1.a.y"+")");
                    #end
                };
            };
            {
                v1.bx=v1.b.x;
                v1.by=v1.b.y;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](v1.bx);
                            ret;
                            #else Math.isNaN(v1.bx);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(v1.bx)"+") :: "+("vec_set(in n: "+"v1.b"+",in x: "+"v1.b.x"+",in y: "+"v1.b.y"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](v1.by);
                            ret;
                            #else Math.isNaN(v1.by);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(v1.by)"+") :: "+("vec_set(in n: "+"v1.b"+",in x: "+"v1.b.x"+",in y: "+"v1.b.y"+")");
                    #end
                };
            };
            {
                v1.vx=v1.bx-v1.ax;
                v1.vy=v1.by-v1.ay;
            };
            v1.w=0.0;
        };
        if(count>1){
            {
                {
                    v2.ax=v2.a.x;
                    v2.ay=v2.a.y;
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](v2.ax);
                                ret;
                                #else Math.isNaN(v2.ax);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(v2.ax)"+") :: "+("vec_set(in n: "+"v2.a"+",in x: "+"v2.a.x"+",in y: "+"v2.a.y"+")");
                        #end
                    };
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](v2.ay);
                                ret;
                                #else Math.isNaN(v2.ay);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(v2.ay)"+") :: "+("vec_set(in n: "+"v2.a"+",in x: "+"v2.a.x"+",in y: "+"v2.a.y"+")");
                        #end
                    };
                };
                {
                    v2.bx=v2.b.x;
                    v2.by=v2.b.y;
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](v2.bx);
                                ret;
                                #else Math.isNaN(v2.bx);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(v2.bx)"+") :: "+("vec_set(in n: "+"v2.b"+",in x: "+"v2.b.x"+",in y: "+"v2.b.y"+")");
                        #end
                    };
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](v2.by);
                                ret;
                                #else Math.isNaN(v2.by);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(v2.by)"+") :: "+("vec_set(in n: "+"v2.b"+",in x: "+"v2.b.x"+",in y: "+"v2.b.y"+")");
                        #end
                    };
                };
                {
                    v2.vx=v2.bx-v2.ax;
                    v2.vy=v2.by-v2.ay;
                };
                v2.w=0.0;
            };
            if(count==3){
                {
                    v3.ax=v3.a.x;
                    v3.ay=v3.a.y;
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](v3.ax);
                                ret;
                                #else Math.isNaN(v3.ax);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(v3.ax)"+") :: "+("vec_set(in n: "+"v3.a"+",in x: "+"v3.a.x"+",in y: "+"v3.a.y"+")");
                        #end
                    };
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](v3.ay);
                                ret;
                                #else Math.isNaN(v3.ay);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(v3.ay)"+") :: "+("vec_set(in n: "+"v3.a"+",in x: "+"v3.a.x"+",in y: "+"v3.a.y"+")");
                        #end
                    };
                };
                {
                    v3.bx=v3.b.x;
                    v3.by=v3.b.y;
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](v3.bx);
                                ret;
                                #else Math.isNaN(v3.bx);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(v3.bx)"+") :: "+("vec_set(in n: "+"v3.b"+",in x: "+"v3.b.x"+",in y: "+"v3.b.y"+")");
                        #end
                    };
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](v3.by);
                                ret;
                                #else Math.isNaN(v3.by);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(v3.by)"+") :: "+("vec_set(in n: "+"v3.b"+",in x: "+"v3.b.x"+",in y: "+"v3.b.y"+")");
                        #end
                    };
                };
                {
                    v3.vx=v3.bx-v3.ax;
                    v3.vy=v3.by-v3.ay;
                };
                v3.w=0.0;
            };
            var old=metric;
            metric=get_metric();
            if(metric<0.5*old||2*old<metric||metric<ZPP_Const.EPSILON)count=0;
        }
        if(count==0){
            count=1;
            v1.a=p1.gverts.front();
            v1.b=p2.gverts.front();
            {
                v1.ax=v1.a.x;
                v1.ay=v1.a.y;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](v1.ax);
                            ret;
                            #else Math.isNaN(v1.ax);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(v1.ax)"+") :: "+("vec_set(in n: "+"v1.a"+",in x: "+"v1.a.x"+",in y: "+"v1.a.y"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](v1.ay);
                            ret;
                            #else Math.isNaN(v1.ay);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(v1.ay)"+") :: "+("vec_set(in n: "+"v1.a"+",in x: "+"v1.a.x"+",in y: "+"v1.a.y"+")");
                    #end
                };
            };
            v1.ia=0;
            {
                v1.bx=v1.b.x;
                v1.by=v1.b.y;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](v1.bx);
                            ret;
                            #else Math.isNaN(v1.bx);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(v1.bx)"+") :: "+("vec_set(in n: "+"v1.b"+",in x: "+"v1.b.x"+",in y: "+"v1.b.y"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](v1.by);
                            ret;
                            #else Math.isNaN(v1.by);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(v1.by)"+") :: "+("vec_set(in n: "+"v1.b"+",in x: "+"v1.b.x"+",in y: "+"v1.b.y"+")");
                    #end
                };
            };
            v1.ib=0;
            {
                v1.vx=v1.bx-v1.ax;
                v1.vy=v1.by-v1.ay;
            };
            v1.w=0.0;
        }
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function get_metric(){
        return switch(count){
            default:0.0;
            case 2:({
                var dx:Float;
                var dy:Float;
                {
                    dx=v1.vx-v2.vx;
                    dy=v1.vy-v2.vy;
                };
                (dx*dx+dy*dy);
            });
            case 3:var ax:Float;
            var ay:Float;
            {
                ax=v2.vx-v1.vx;
                ay=v2.vy-v1.vy;
            };
            var bx:Float;
            var by:Float;
            {
                bx=v3.vx-v1.vx;
                by=v3.vy-v1.vy;
            };
            (by*ax-bx*ay);
        }
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function write(count:Int,v1:ZPP_SVertex,v2:ZPP_SVertex,v3:ZPP_SVertex){
        this.count=count;
        this.v1=v1;
        this.v2=v2;
        this.v3=v3;
        metric=get_metric();
    }
}
